﻿using System;
using System.Data.SqlTypes;
using sqlserverextensions.Helper;

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString StringFormat(SqlString value, SqlString format)
    {
        Int16 errSeverity = 16;

        try
        {
            if (value.IsNull)
                value = "";

            string formatString = "{0:" + format.Value + "}";

            return String.Format(formatString, value.Value);
        }
        catch (Exception ex)
        {
            ExceptionHelper.EvaluateException(ex, errSeverity);
            return null;
        }
    }
};

